#pragma once
#include <map>
#include <functional>
#include "logmessage.hpp"
namespace zty
{
    class Task
    {
        static std::map<char, std::function<int(int, int)>> s_opmap;

    public:
        int _l;
        int _r;
        char _op;

        Task() = default;
        Task(int l, int r, char op)
            : _l(l),
              _r(r),
              _op(op)
        {
        }

        int operator()()
        {
            if ((_op == '/' || _op == '%') && _r == 0)
            {
                LogMessage(ERROR, "Divided By Zero!");
                return -1;
            }
            return s_opmap[_op](_l, _r);
        }
    };

    std::map<char, std::function<int(int, int)>> Task::s_opmap{
        {'+', [](int l, int r) -> int
         { return l + r; }},
        {'-', [](int l, int r) -> int
         { return l - r; }},
        {'*', [](int l, int r) -> int
         { return l * r; }},
        {'/', [](int l, int r) -> int
         { return l / r; }},
        {'%', [](int l, int r) -> int
         { return l % r; }}};
}